using System;
using System.IO;
using System.Net;

namespace RStein.Posterous.API
{
    #if SILVERLIGHT
    internal static class WebRequestExtensions
    {
        public static WebResponse GetResponse(this WebRequest request)
        {
            checkRequestNotNull(request);

            return AsyncHelper.RunAsync(request.BeginGetResponse, request.EndGetResponse);
        }

        
        public static Stream GetRequestStream(this WebRequest request)
        {
            checkRequestNotNull(request);
            return AsyncHelper.RunAsync(request.BeginGetRequestStream, request.EndGetRequestStream);
        }

        private static void checkRequestNotNull(WebRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException();
            }
        }


    }
    #endif
}